import { isWeChatBrowser } from '@/config/h5/index'
import appBackMainPage from '@/services/h5/app-api/appBackMainPage.js'
import { isApp } from '@/utils/platform'
export default {
  data() {
    return {}
  },
  methods: {
    async judgeProductClick(item) {
      if (
        item.needLogin === 'Y' &&
        !localStorage.getItem(process.env.VUE_APP_USER_KEY)
      ) {
        if (isApp) {
          appBackMainPage({
            pageIndex: '3'
          })
        } else {
          this.$router.push('/login')
        }
        return false
      }
      //  微信工银标识
      let flag = !!item.salesChannels.toLocaleLowerCase().match(/wx/)
      if (item.isOnline === 'N' && isWeChatBrowser && !flag) {
        this.$toast('本产品不支持微信端投保，请到APP内投保')
        return
      }

      if (process.env.VUE_APP_ENV === 'development') {
        if (item.isOnline == 'Y') {
          if(item.productUrl.indexOf("userId") > -1) {
            let userId = item.productUrl.substr(item.productUrl.indexOf("userId=")+7)
            // console.log("userId",userId,item.productUrl,item.productUrl.indexOf("userId="))
            window.location.href = `http://localhost:8080/#/consulting?productId=${item.productId}&productName=${item.productName}&userId=${userId}`
          } else {
            window.location.href = `http://localhost:8080/#/consulting?productId=${item.productId}&productName=${item.productName}`
          }
          
        } else {
          if (item.isCarFlag == 'Y') {
            window.location.href = `http://localhost:8080/#/car?productId=${item.productId}&productName=${item.productName}`
          } else {
            window.location.href = `http://localhost:8080/#/productOffline?productId=${item.productId}&productName=${item.productName}`
          }
        }
      } else {
        // window.location.href = `${item.productUrl}`
        if (isWeChatBrowser) {
          window.location.href = `${item.productUrl}&productName=${item.productName}`
        } else {
          window.location.href = `${item.productUrl}`
        }
      }
    }
  }
}
